﻿using Application.AppService.ERAppService;
using Application.AppService.HFAppService;
using Application.AppService.SGAppService;
using Application.AppService.SGDAppService;
using Application.AppService.SSAppServoice;
using Application.Service;
using AutoMapper;
using Domain;
using Domain.Entity;
using Hangfire;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System;

namespace UI.Controllers.Salary_management_薪酬发放管理_
{
    public class PayrollRegistrationController : Controller
    {
        private readonly IHFAppService hfAppServoice;
        private readonly ISGDAppService sGDAppService;
        private readonly ISGAppService sGAppService;
        private readonly ISalaryService salaryService;
        private readonly IMapper mapper;

        public PayrollRegistrationController(IHFAppService hfAppServoice, IMapper mapper, ISGDAppService sGDAppService, ISGAppService sGAppService, ISalaryService salaryService)
        {
            this.hfAppServoice = hfAppServoice;
            this.sGDAppService = sGDAppService;
            this.sGAppService = sGAppService;
            this.salaryService = salaryService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Index1()
        {
            return View();
        }
        public IActionResult Index2()
        {
            return View();
        }

        [HttpPost("SelectHFQ")]
        public IActionResult SelectHFQ(string zhi)
        {
            HFQuery hf = hfAppServoice.SelectHFQAsync(zhi);
            return Json(hf);
        }
        /// <summary>
        /// 新增薪酬发放详细信息表
        /// </summary>
        /// <param name="sgd">薪酬发放详细信息表</param>
        /// <returns></returns>
        [HttpPost("AddSGD")]
        public async Task<IActionResult> AddSGD(SGD sgd) 
        {
            bool rs = await sGDAppService.AddSgdAsync(sgd);
            return Json(rs);
        }

        /// <summary>
        /// 新增薪酬发放信息表
        /// </summary>
        /// <param name="sg">薪酬发放信息表</param>
        /// <returns></returns>
        [HttpPost("AddSG")]
        public async Task<IActionResult> AddSG(SGAddDto sgadd)
        {
            SG sg = mapper.Map<SG>(sgadd);
            bool rs = await sGAppService.AddSgAsync(sg);
            return Json(rs);
        }

        [HttpPost("SalaryAsync")]
        public async Task<IActionResult> SalaryAsync(string humanId, int zt)
        {
            bool rs = await salaryService.Salary(humanId, zt);
            return Json(rs);
        }

        [HttpPost("XGHumanFileStatus")]
        public async Task<IActionResult> XGHumanFileStatus(string humanId, double DemandSalaraySum, double PaidSalarySum)
        {
            bool rs = await hfAppServoice.RemoveHFQAsyncHFS(humanId, DemandSalaraySum,PaidSalarySum);
            return Json(rs);
        }

    }
}
